package com.taylor.community.util;

public class RedisKeyUtil {
    private static final String SPLIT = ":";
    //key的前缀
    private static final String PREFIX_ENTITY_LIKE = "like:entity";
    private static final String PREFIX_USER_LIKE = "like:user";
    //关注者
    private static final String PREFIX_FOLLOWEE = "followee";
    //粉丝
    private static final String PREFIX_FOLLOWER = "follower";
    //验证码
    private static final String PREFIX_CAPTCHA = "captcha";
    //登录凭证
    private static final String PREFIX_TICKET = "ticket";
    //用户user
    private static final String PREFIX_USER = "user";
    //UV(Unique Visitor)根据ip去重统计
    private static final String PREFIX_UV = "uv";
    //DAU(Daily Active User)根据用户的id进行统计
    private static final String PREFIX_DAU = "dau";
    //统计帖子分数
    private static final String PREFIX_POST = "post";
    /**
     * 存储热帖
     */
    private static final String PREFIX_HOTPOST= "hotPost";
    /**
     * 帖子总数
     */
    public static final String PREFIX_TOTALPOST= "totalPost";
    /**
     * 用set存储点赞的用户的id 便于将来业务的扩展
     * 最终拼成的格式 like:entity:entityType:entityId
     *
     * @param entityType
     * @param entityId
     * @return
     */
    public static String getEntityLikeKey(int entityType, int entityId) {
        return PREFIX_ENTITY_LIKE + SPLIT + entityType + SPLIT + entityId;
    }

    /**
     * 数据类型为普通的字符串
     *
     * @param userId
     * @return
     */
    //用单独的数据记录 某用户收到的赞
    public static String getUserLikeKey(int userId) {
        return PREFIX_USER_LIKE + SPLIT + userId;
    }

    /**
     * 某个用户关注的实体
     * key：这个用户的id是多少、关注的实体的类型是什么
     * followee:userId:entityType -> zset(entityId,now)
     * 通过关注的时间进行排序 相当于时间就是有序列表的分数
     *
     * @param userId     该用户的id
     * @param entityType
     * @return
     */
    public static String getFolloweeKey(int userId, int entityType) {
        return PREFIX_FOLLOWEE + SPLIT + userId + SPLIT + entityType;
    }

    /**
     * 某个实体拥有的粉丝
     * key：这个实体是什么类型、id是多少
     * follower:entityType:entityId -> zset(userId,now)
     *
     * @param entityType
     * @param entityId
     * @return
     */
    public static String getFollowerKey(int entityType, int entityId) {
        return PREFIX_FOLLOWER + SPLIT + entityType + SPLIT + entityId;
    }

    /**
     * 生成验证码
     *
     * @param owner 用户的临时凭证
     * @return
     */
    public static String getCaptchaKey(String owner) {
        return PREFIX_CAPTCHA + SPLIT + owner;
    }

    //登录凭证
    public static String getTicketKey(String ticket) {
        return PREFIX_TICKET + SPLIT + ticket;
    }

    //用户user
    public static String getUserKey(int userId) {
        return PREFIX_USER + SPLIT + userId;
    }

    //单日UV
    public static String getUvKey(String date) {
        return PREFIX_UV + SPLIT + date;
    }

    //区间UV
    public static String getUvKey(String startDate, String endDate) {
        return PREFIX_UV + SPLIT + startDate + SPLIT + endDate;
    }

    //DAU
    public static String getDauKey(String date) {
        return PREFIX_DAU + SPLIT + date;
    }

    //区间DAU
    public static String getDauKey(String startDate, String endDate) {
        return PREFIX_DAU + SPLIT + startDate + SPLIT + endDate;
    }
    //帖子分数
    public static String getPostScoreKey(){
        return PREFIX_POST + SPLIT + "score";
    }
    /**
     * 突然想到直接用跟caffeine一样将整个有序链表放到一个键值对的value中不就好了
     * 所以数据类型使用list
     */
    public static String getHotpost(int offset, int limit){
        return PREFIX_HOTPOST + SPLIT + offset + SPLIT + limit;
    }
}


